//用户信息数据
function createUserList() {
  return [
    {
      userId: 1,
      avatar:
        'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      account: 'admin',
      password: '123456',
      desc: '平台管理员',
      roles: ['admin', 'test'],
      buttons: ['cuser.detail'],
      routes: ['home'],
      token: 'Admin Token',
    },
    {
      userId: 2,
      avatar:
        'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
      account: 'test',
      password: '123456',
      desc: '测试管理员',
      roles: ['test'],
      buttons: ['cuser.detail', 'cuser.user'],
      routes: ['home'],
      token: 'System Token',
    },
  ]
}
import { mock } from "mockjs"


export default [
  // 用户登录接口
  {
    url: '/mock/sysUser/sysUserLogin',//请求地址
    method: 'post',//请求方式
    timeout: 200,
    response: ({ body }: any) => {
      //获取请求体携带过来的用户名与密码
      const { account, password } = body
      //调用获取用户信息函数,用于判断是否有此用户
      const checkUser = createUserList().find(
        (item) => item.account === account && item.password === password,
      )
      //没有用户返回失败信息
      if (!checkUser) {
        return { code: 201, data: false, msg: "账号或者密码不正确" }
      }
      //如果有返回成功信息
      const { token } = checkUser
      return { code: 200, data: token }
    },
  },
  // 获取用户信息
  {
    url: '/mock/sysUser/getSysUserAndRoleInfoByToken',
    method: 'post',
    response: (request: any) => {
      //获取请求头携带token
      const token = request.headers.token;
      //查看用户信息是否包含有次token用户
      const checkUser = createUserList().find((item) => item.token === token)
      //没有返回失败的信息
      if (!checkUser) {
        return { code: 201, data: false, msg: '获取用户信息失败' }
      }
      //如果有返回成功信息
      return { code: 200, data: checkUser }
    },
  },
  // 查询接口
  {
    url: '/mock/sysUser/getSysUserAndRoleInfoPage',
    method: 'post',
    timeout: 500,
    response: ({ body }: any) => {
      const { pageNo, pageSize } = body
      let recordsList = [] as any
      for (let index = 0; index < pageSize; index++) {
        recordsList.push(mock({
          id: "@id",
          userName: "@cname",
          "account|11": '@integer(1, 9)',
          'isMultiLogin|1': [1, 0],
          'state|1': [1, 0],
          "roles|1-2": [
            {
              'roleCode|1': ['admin', 'test'],
              "roleName|1": ['超级管理员', '普通管理员'],
              roleStatus: "1"
            },
          ],
        },))
      }
      return {
        code: 200,
        data: mock({
          "size": pageSize,
          "current": pageNo,
          "records": recordsList,
          "total": 188,
        })
      }
    },
  },
  {
    url: '/mock/sysUser/saveOrUpdateSysUserUserRole',
    method: 'post',
    response: ({ body }: any) => {
      return {
        code: 201,
        data: null,
        msg: '演示模式无法操作'
      }
    }
  },
  {
    url: '/mock/sysUser/removeSysUserAndSysUserRoleByAccount',
    method: 'post',
    response: ({ body }: any) => {
      return {
        code: 201,
        data: null,
        msg: '演示模式无法操作'
      }
    }
  },
]